NotificationManagerCompat

Compatibility library for NotificationManager with fallbacks for older platforms.

To use this class, call the static function from to get a NotificationManagerCompat object, and then call one of its methods to post or cancel notifications.

Types

Link copied to clipboard
Link copied to clipboard
Helper class which encapsulates a Notification, its id, and optionally a tag, for use when batch-posting a number of notifications.

Properties

Link copied to clipboard
val ACTION_BIND_SIDE_CHANNEL: String = "android.support.BIND_NOTIFICATION_SIDE_CHANNEL"
Intent action to register for on a service to receive side channel notifications.
Link copied to clipboard
val EXTRA_USE_SIDE_CHANNEL: String = "android.support.useSideChannel"
Notification extras key: if set to true, the posted notification should use the side channel for delivery instead of using notification manager.
Link copied to clipboard
Default notification importance: shows everywhere, allowed to makes noise, but does not visually intrude.
Link copied to clipboard
Higher notification importance: shows everywhere, allowed to makes noise and peek.
Link copied to clipboard
Low notification importance: shows everywhere, but is not intrusive.
Link copied to clipboard
Highest notification importance: shows everywhere, allowed to makes noise, peek, and use full screen intents.
Link copied to clipboard
Min notification importance: only shows in the shade, below the fold.
Link copied to clipboard
A notification with no importance: shows nowhere, is blocked.
Link copied to clipboard
Value signifying that the user has not expressed an importance.
Link copied to clipboard
Interruption filter constant - Alarms only interruption filter - all notifications except those of category CATEGORY_ALARM are suppressed.
Link copied to clipboard
Interruption filter constant - Normal interruption filter - no notifications are suppressed.
Link copied to clipboard
Interruption filter constant - No interruptions filter - all notifications are suppressed and all audio streams (except those used for phone calls) and vibrations are muted.
Link copied to clipboard
Interruption filter constant - Priority interruption filter - all notifications are suppressed except those that match the priority criteria.
Link copied to clipboard
Interruption filter constant - returned when the value is unavailable for any reason.

Functions

Link copied to clipboard
Returns whether notifications from the calling package are not blocked.
Link copied to clipboard
open fun cancel(id: Int)
open fun cancel(@Nullable tag: @Nullable String, id: Int)
Cancel a previously shown notification.
Link copied to clipboard
open fun cancelAll()
Cancel all previously shown notifications.
Link copied to clipboard
Returns whether the calling app's properly formatted notifications can appear in a promoted format, which may result in higher ranking, appearances on additional surfaces, and richer presentation.
Link copied to clipboard
Returns whether the calling app can send fullscreen intents.
Link copied to clipboard
open fun createNotificationChannel(@NonNull channel: @NonNull NotificationChannel)
open fun createNotificationChannel(@NonNull channel: @NonNull NotificationChannelCompat)
Creates a notification channel that notifications can be posted to.
Link copied to clipboard
open fun createNotificationChannelGroup(@NonNull group: @NonNull NotificationChannelGroup)
Creates a group container for NotificationChannel objects.
Link copied to clipboard
open fun createNotificationChannelGroups(@NonNull groups: @NonNull List<NotificationChannelGroup>)
Creates multiple notification channel groups.
Link copied to clipboard
Creates multiple notification channel groups.
Link copied to clipboard
open fun createNotificationChannels(@NonNull channels: @NonNull List<NotificationChannel>)
Creates multiple notification channels that different notifications can be posted to.
Link copied to clipboard
open fun createNotificationChannelsCompat(@NonNull channels: @NonNull List<NotificationChannelCompat>)
Creates multiple notification channels that different notifications can be posted to.
Link copied to clipboard
open fun deleteNotificationChannel(@NonNull channelId: @NonNull String)
Deletes the given notification channel.
Link copied to clipboard
open fun deleteNotificationChannelGroup(@NonNull groupId: @NonNull String)
Deletes the given notification channel group, and all notification channels that belong to it.
Link copied to clipboard
open fun deleteUnlistedNotificationChannels(@NonNull channelIds: @NonNull Collection<String>)
Deletes notification channels for which ids are NOT given.
Link copied to clipboard
@NonNull
open fun from(@NonNull context: @NonNull Context): @NonNull NotificationManagerCompat
Get a NotificationManagerCompat instance for a provided context.
Link copied to clipboard
@NonNull
open fun getActiveNotifications(): @NonNull List<StatusBarNotification>
Recover a list of active notifications: ones that have been posted by the calling app that have not yet been dismissed by the user or canceled by the app.
Link copied to clipboard
Gets the current notification interruption filter.
Link copied to clipboard
@NonNull
open fun getEnabledListenerPackages(@NonNull context: @NonNull Context): @NonNull Set<String>
Get the set of packages that have an enabled notification listener component within them.
Link copied to clipboard
open fun getImportance(): Int
Returns the user specified importance for notifications from the calling package.
Link copied to clipboard
@Nullable
open fun getNotificationChannel(@NonNull channelId: @NonNull String): @Nullable NotificationChannel
Returns the notification channel settings for a given channel id.
@Nullable
open fun getNotificationChannel(@NonNull channelId: @NonNull String, @NonNull conversationId: @NonNull String): @Nullable NotificationChannel
Returns the notification channel settings for a given channel and conversation id.
Link copied to clipboard
@Nullable
open fun getNotificationChannelCompat(@NonNull channelId: @NonNull String): @Nullable NotificationChannelCompat
Returns the notification channel settings for a given channel id.
@Nullable
open fun getNotificationChannelCompat(@NonNull channelId: @NonNull String, @NonNull conversationId: @NonNull String): @Nullable NotificationChannelCompat
Returns the notification channel settings for a given channel and conversation id.
Link copied to clipboard
@Nullable
open fun getNotificationChannelGroup(@NonNull channelGroupId: @NonNull String): @Nullable NotificationChannelGroup
Returns the notification channel group settings for a given channel group id.
Link copied to clipboard
@Nullable
open fun getNotificationChannelGroupCompat(@NonNull channelGroupId: @NonNull String): @Nullable NotificationChannelGroupCompat
Returns the notification channel group settings for a given channel group id.
Link copied to clipboard
Returns all notification channel groups belonging to the calling app or an empty list on older SDKs which don't support Notification Channels.
Link copied to clipboard
Returns all notification channel groups belonging to the calling app or an empty list on older SDKs which don't support Notification Channels.
Link copied to clipboard
@NonNull
open fun getNotificationChannels(): @NonNull List<NotificationChannel>
Returns all notification channels belonging to the calling app or an empty list on older SDKs which don't support Notification Channels.
Link copied to clipboard
Returns all notification channels belonging to the calling app or an empty list on older SDKs which don't support Notification Channels.
Link copied to clipboard
Post a number of notifications, to be shown in the status bar, stream, etc.
open fun notify(id: Int, @NonNull notification: @NonNull Notification)
open fun notify(@Nullable tag: @Nullable String, id: Int, @NonNull notification: @NonNull Notification)
Post a notification to be shown in the status bar, stream, etc.